package com.example.service.impl;

import com.example.mapper.StudentMapper;
import com.example.pojo.Degree;
import com.example.pojo.PageResult;
import com.example.pojo.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceimpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    //分页查询学生列表
    @Override
    public PageResult findAll(Integer page, Integer pageSize) {
        Long total = studentMapper.count();
        Integer start = (page-1)*pageSize;
        List<Student> rows = studentMapper.list(start,pageSize);
        return new PageResult(total,rows);
    }
    //添加学生
    @Override
    public void save(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.save(student);
    }
    //删除学生
    @Override
    public void delete(String ids) {
        studentMapper.delete(ids);
    }
    //根据id查询学生
    @Override
    public Student getById(Integer id) {
        Student student = (Student) studentMapper.getById(id);
        return student;
    }
    //修改学生
    @Override
    public void update(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);
    }
    //修改学生违规次数和违规分数
    @Override
    public void updateViolation(Integer id, Short score) {
        studentMapper.updateViolation(id,score);
    }



    @Override
    public Degree getEmpGenderData() {
        List<Map<String, Long>> genderList = studentMapper.getEmpGenderData();
        return null;
    }
}
